package aibkTestReview.quesWrongTutor.aibkTutorPPT

import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import androidx.appcompat.app.AppCompatActivity
import com.lancoo.znbkxx.teacher.R
import com.lancoo.znbkxx.teacher.aibkTestCoach.kBase.KBaseRecyclerAdapter
import com.lancoo.znbkxx.teacher.aibkTestCoach.kBase.KBaseRecyclerViewHolder
import com.lancoo.znbkxx.teacher.aibkTestCoach.networkRequest.entity.PaperEvaluationInfor
import com.lancoo.znbkxx.teacher.aibkTestCoach.paperToEvaluation.PaperEvaluationInforIndexHelp.getChildListBean
import com.lancoo.znbkxx.teacher.widget.CustomTextViewToPicture
import kotlinx.android.synthetic.main.aibk_adapter_item_table.view.*

class EvaluationAdapterChildTable(
        val activity: AppCompatActivity,
        val paperEvaluationInfor: PaperEvaluationInfor,
        val index_A:Int,
        val index_B:Int,
        val index_C:Int,
        val itemAnswer:String
) : KBaseRecyclerAdapter() {

    override fun getHolderView(parent: ViewGroup?, position: Int): View? {
        return LayoutInflater.from(activity)
                .inflate(R.layout.aibk_adapter_item_table, parent, false)
    }

    override fun onBindViewHolder(holder: KBaseRecyclerViewHolder, position: Int) {
        val optionIndex = getChildListBean(paperEvaluationInfor, index_A, index_B, index_C).ChildOptionList[position].OptionIndex
        val stuCount = getChildListBean(paperEvaluationInfor, index_A, index_B, index_C).ChildOptionList[position].StuCount
        val rate = getChildListBean(paperEvaluationInfor, index_A, index_B, index_C).ChildOptionList[position].Rate

        holder.convertView.TvOptionIndex.text = optionIndex
        CustomTextViewToPicture(activity, holder.convertView.TvOptionChooseInfor, "$stuCount<br>$rate")
        if(itemAnswer == optionIndex){
            holder.convertView.TvOptionIndex.setBackgroundResource(R.drawable.aibk_background_table_dark_blue)
            holder.convertView.TvOptionIndex.setTextColor(activity.resources.getColor(R.color.lancoooWhite))
            holder.convertView.TvOptionChooseInfor.setTextColor(activity.resources.getColor(R.color.lancoooBlue))
        }else{
            holder.convertView.TvOptionIndex.setBackgroundResource(R.drawable.aibk_background_table_light_blue)
            holder.convertView.TvOptionIndex.setTextColor(activity.resources.getColor(R.color.lancoooBlue))
            holder.convertView.TvOptionChooseInfor.setTextColor(activity.resources.getColor(R.color.textColor))
        }
    }

    override fun getItemCount(): Int {
        return getChildListBean(paperEvaluationInfor, index_A, index_B, index_C).ChildOptionList.size
    }

    override fun getItemViewType(position: Int): Int {
        return position
    }

    override fun getItemId(position: Int): Long {
        return position.toLong()
    }

}